﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using WxBean.Core.Common.Helper;
using WxBean.Core.Common.PythonCodeFile;
using WxBean.Core.IServices;
using WxBean.Core.Model;
using WxBean.Core.Model.Models;
using WxBean.Core.Services.BASE;

namespace WxBean.Core.Services
{
    public class VideoService : BaseServices<VideoModel>, IVideoService
    {
        //public IRedisCacheManager _redisCacheManager { get; set; }

        private IWebBasicService _webBasicService { get; set; }

        public VideoService(IWebBasicService webBasicService)
        {
            //_redisCacheManager = redisCacheManager;

            _webBasicService = webBasicService;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public async Task<MessageModel<IEnumerable<VideoModel>>> ExecuteAsync(string name)
        {
            var list = new List<VideoModel>();
            var result = new MessageModel<IEnumerable<VideoModel>>();
            var videoList = await Query(q => q.Name == name);
            //_redisCacheManager.watch
            if (videoList != null && videoList.Count > 0)
            {
                list.AddRange(videoList);
            }
            var webBasicList = await _webBasicService.Query(q => q.WebType == WebSiteType.Video && q.Action == true);
            //if (!webBasicList?.Any() ?? true)
            //{

            //}
            foreach (var item in webBasicList)
            {
                var filePath = @"D:\Fiddler\Video.txt";
                await ExecutePythonAsync(item);

                var fileStr = FileHelper.ReadFile(filePath);
            }

            return new MessageModel<IEnumerable<VideoModel>>()
            {
                msg = "获取成功",
                success = true,
                response = list
            };
    }

        /// <summary>
        /// 执行python 脚本
        /// </summary>
        /// <returns></returns>
        public async Task ExecutePythonAsync(WebBasic web)
        {
            await Console.Out.WriteLineAsync("开始执行Python脚本");
            RunPython run = new RunPython();
            run.RunPythonAsync();
        }
    }
}
